<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>全部线索</title>
<link rel="stylesheet" type="text/css" href="<%=path%>/bc/bootstarp/css/bootstrap.min.css" /> 
<link rel="stylesheet" type="text/css" href="<%=path%>/bc/css/public.css" />
<link rel="stylesheet" type="text/css" href="<%=path%>/bc/css/index.css" />
<link rel="stylesheet" type="text/css" href="<%=path%>/bc/css/app.css" />
<link rel="stylesheet" type="text/css" href="<%=path%>/bc/css/set.css" />
<link rel="stylesheet" type="text/css" href="<%=path%>/css/highlight.css" />
<style type="text/css">
	.s_content{
		top: 0;
		left: 0;
		width: 100%;
	}
</style>
<style>
	.into {
	    display: inline-block;
	    height: 10px;
	    width: 10px;
	    border-top: 1px solid #03a9f4;
	    border-left: 1px solid #03a9f4;
	    -webkit-transform: rotate(-225deg) skew(0deg);
	    transform: rotate(-225deg) skew(0deg);
	    position: absolute;
	    right: 20%;
	    bottom: -6px;
	}

	.s_into{
		left: 10%;
	    bottom: -6px;
	}

	.k_into{
		top: -48px;
	    left: 94px;
	    -webkit-transform: rotate(-135deg) skew(0deg);
	    transform: rotate(-135deg) skew(0deg);
	}		
</style>
</head>
<body>
<div class="s_content fix">
    <div class="m_xmanage" path="<%=path%>">
        <a href="javascript:;" class="on">全部</a>
        <a href="javascript:;">微博线索</a>
        <a href="javascript:;">活动线索</a>
        <a href="javascript:;">智能营销线索</a>
    </div>
    <div class="s_container">
        <ol class="surrent fix">
            <div class="s_clue s_keyword">
                <p>
                    <span>0</span> 条线索源于关注关键字
                    <i style="padding-top: 10px;"><img src="<%=path%>/bc/images/icon_microblog.png"/></i>
                </p>
                <ul class="s_source fix">
                </ul>
            </div>
            <div class="s_all s_all_little">
                <img src="<%=path%>/bc/images/sjx.png" class="s_sjx" />
                <ul class="s_all_title fix">
                    <li class="s_all_on"><a href="javascript:;">最新</a></li>
                    <b><a href="javascript:;">更多</a></b>
                </ul>
                <table>
                    <tbody>
                    </tbody>                
                </table>
            </div>
            
            <div style="clear: both;height: 0.001;"></div>
            
            <div class="s_clue s_keyword">
                <p>
                    <span>0</span> 条线索源于活动
                </p>
                <ul class="s_source fix">
                </ul>
            </div>
            <div class="s_all s_all_little" style="margin-bottom:16px;">
                <img src="<%=path%>/bc/images/sjx.png" class="s_sjx" />
                <ul class="s_all_title fix">
                    <li class="s_all_on"><a href="javascript:;">全部</a></li>
                    <b><a href="javascript:;">更多</a></b>
                </ul>
                <table class="s_table">
                    <tbody>
                    </tbody>                
                </table>
            </div>
            <div class="pad2" style="margin-bottom:100px">
                    
            </div>
               
        </ol>
    </div>
</div>

<div class="s_popup_box j_popup_box">
    <div class="s_popup_detailed show">
        <h4><img src="<%=path%>/sys/set/images/warning.png" />删除信息</h4>
        <h5>确定要删除此账号吗？</h5>
        <p><a href="javascript:;" class="j_popup_box_cancel" onclick="javascript:$(this).parents('.j_popup_box').hide();">取消</a> <a href="javascript:;" class="j_popup_box_confirm">确定</a></p>
    </div>
</div>
</body>
<script type="text/javascript" src="<%=path%>/bc/bootstarp/js/jquery.min.js"></script>
<script type="text/javascript" src="<%=path%>/bc/js/clue_title.js"></script>
<script type="text/javascript" src="<%=path%>/bm/js/jquery.cookie.js"></script>   
<script type="text/javascript" src="<%=path%>/js/jquery.highlight.js"></script>
<script type="text/javascript">
var startIndex = 0;
var pageSize = 5;
var keyWord_weibo = "";
var keyWord_activity = "";
var currentPage = 1;
var pageCount = 0;

var customerId = 0;	//客户id
var actionId = 0;	//客户行为id
var clueWeiboId = 0;//微博线索id

var access_token=$.cookie('access_token');
var cid=$.cookie('cid');
var uid=$.cookie('uid');

$(function(){
	init();
	
	$(document).on('click','.s_all_title:eq(0) li,.s_source:eq(0)>li',function(){
		if(keyWord_weibo != $(this).attr("keyWord")){
			keyWord_weibo = $(this).attr("keyWord");
    	    initWeibo();
		}
    });
	
	$(document).on('click','.s_all:eq(1) .s_all_title li,.s_source:eq(1)>li',function(){
		if(keyWord_activity != $(this).attr("keyWord")){
			keyWord_activity = $(this).attr("keyWord");
			initActivity();
		}
    });
	
	/*聊天点击开始*/
	$(document).on("click",".s_icon_dialogue",function(){
		//初始化数据，全部设置0
		top.customerId = 0;
		top.actionId = 0;
		top.clueWeiboId = 0;
		top.writeOffId = 0;
		
		customerId = $(this).attr("customerId");
		actionId = $(this).attr("actionId");
		clueWeiboId = $(this).attr("clueWeiboId");
		
		top.customerId = customerId;
		top.actionId = actionId;
		top.clueWeiboId = clueWeiboId;
		
<%-- 		$.post("<%=path%>/api/customer_action/customerChatView",function(data){ --%>
			var d = top.dialog({
				fixed: true,
				zIndex: 10000,
				padding:0,
				width:1172,
				height:568,
				title:'沟通记录',
// 				content:data,
				url:"<%=path%>/api/customer_action/customerChatView",
				cancelDisplay: false,
				cancel: function () {
					if(top.customerChatChange == 1){
						top.customerChatChange = 0;
					}
					top.customerId = 0;
					top.actionId = 0;
					top.clueWeiboId = 0;
					return true;
				}
			});
			d.showModal();
// 		})
	});
	/*聊天点击结束*/
});

function init(){
	initActivity();
	getMarket();
	$.post("${pageContext.request.contextPath}/api/weibo/showfirstpage",function(data){
		data = eval(data);
		if(data.showstatus == 1){
			//initWeibo();
		}else if(data.showstatus == 0){
			$(".m_xmanage>a:eq(1)").css("display","none");
			$(".s_container .s_clue:eq(0),.s_container .s_all:eq(0)").css("display","none");
		}
	});
	initWeibo();
}

function initWeibo(){
	$.post('<%=path%>/api/clue_customer/clue_weibo',{"startIndex":startIndex,"pageSize":pageSize,"keyWord":keyWord_weibo},function(data){
		data = JSON.parse(data);
		
		weiboFirst(data.key_word_list,data.weibo_keyword_count);
		
		weiboSecond(data.weibo_clue_list,data.weibo_keyword_count);
		
		parent.changeFrameHeight();
	});
}

function initActivity(){
	$.post('<%=path%>/api/clue_customer/clue_activity',{"startIndex":startIndex,"pageSize":pageSize,"keyWord":keyWord_activity},function(data){
		data = JSON.parse(data);
		
		activityFirst(data.activity_name_list,data.weibo_activity_count);
		
		activitySecond(data.activity_clue_list);
		
		parent.changeFrameHeight();
	});
}

function weiboFirst(key_word_list,keyword_count){
	//首先判断是否绑定微博
	$.ajax({
		async:false,
		url:"<%=path%>/api/weibo/changebind",
		type:"POST",
		dataType:"json",
		success:function(data){
			if(data.error_code==1 || data.RemainingDay<=0){
				$(".s_clue:eq(0)>p>span").text(0);
				$(".s_source:eq(0)").html('<div class="k_empty_content"><img src="<%=path%>/bc/images/icon_wb.png" /><p>您还没有绑定微博 <a href="${pageContext.request.contextPath}/ui/wbbangding" target="_parent">去绑定></a></p></div>');
				
				$(".s_all:eq(0)>.s_all_title").html('<img src="<%=path%>/bc/images/sjx.png" class="s_sjx" /><div class="s_all_title fix"><span>暂无关键字</span><a href="javascript:;" onclick="hideWeibo()">隐藏</a></div>');
				$(".s_all:eq(0)>.s_all_title").addClass("k_empty");
			}
		}
	});
	
	//如果没有绑定微博，退出
	if($(".s_all:eq(0)>.s_all_title").hasClass("k_empty")){
		return ;
	}
	
	
	var total = 0;
	
	var startStr = "";
	var endStr = "";
	
	$(".s_all:eq(0)>.s_all_title").html('<li class="s_all_on" keyWord=""><a href="javascript:;">最新</a></li>');
	
	for ( var i = 0; i < keyword_count.length; i++) {
		var a = keyword_count[i];
		total += a.count;
	}
	
	for ( var i = 0; i < keyword_count.length; i++) {
		var a = keyword_count[i];

		for ( var j = 0; j < key_word_list.length; j++ ) {
			var b = key_word_list[j];

			if(a.keyWord == b){
		        $(".s_all:eq(0)>.s_all_title").append('<li keyWord="'+a.keyWord+'"><a href="javascript:;">'+a.keyWord+'</a></li>');
				key_word_list.splice(j,1);
				startStr += '<li keyWord="'+a.keyWord+'"><i><a href="javascript:;">'+a.keyWord+'</a></i><div class="progressbar_1"><div class="bar" style="width:'+(a.count/total*100)+'%;"></div></div><em style="padding-left:10px">'+a.count+'条</em></li>';
			}
		}
	}
	for ( var i = 0; i < key_word_list.length; i++) {
		var a = key_word_list[i];
		if(a != ""){
			endStr += '<li keyWord="'+a+'"><i><a href="javascript:;">'+a+'</a></i><div class="progressbar_1"><div class="bar" style="width:2%;"></div></div><em style="padding-left:10px">0条</em></li>';
			$(".s_all:eq(0)>.s_all_title").append('<li keyWord="'+a+'"><a href="javascript:;">'+a+'</a></li>');
		}
	}
	

	$(".s_clue:eq(0)>p>span").text(total);
	
	if(startStr+endStr != ""){
		$(".s_source:eq(0)").html(startStr+endStr);
		$(".s_all:eq(0)>.s_all_title").append('<b><a href="<%=path%>/api/clue_customer/clue_weiboView">更多</a></b>');
	}else{
		$(".s_clue:eq(0)>p>span").text(0);
		$(".s_source:eq(0)").html('<div class="k_empty_content"><img src="<%=path%>/bc/images/icon_wb.png" /><p>您还没有添加关键字 <a href="${pageContext.request.contextPath}/ui/wbbangding" target="_parent">去添加></a></p></div>');
		
		$(".s_all:eq(0)>.s_all_title").html('<img src="<%=path%>/bc/images/sjx.png" class="s_sjx" /><div class="s_all_title fix"><span>暂无关键字</span><a href="javascript:;" onclick="hideWeibo()">隐藏</a></div>');
		$(".s_all:eq(0)>.s_all_title").addClass("k_empty");
	}
	
	$(".s_all:eq(0)>.s_all_title>li[keyWord='"+keyWord_weibo+"']").addClass('s_all_on').siblings().removeClass();
}

function weiboSecond(weibo_clue_list,keyword_count){
	var tr = "";
	if(!$(".s_all:eq(0)>.s_all_title").hasClass("k_empty")){
		for(var i = 0; i < weibo_clue_list.length; i++){
			var a = weibo_clue_list[i];
			if(a.content.length>=64){
				a.content = a.content.substr(0,60)+"...";
			}
			tr += '<tr><td><img style="height:50px;width:50px;" src="'+((a.avatar == null || a.avatar == undefined || a.avatar == "") ? "<%=path%>/images/000head_pic.png" : a.avatar)+'"/></td><td><i>'+a.screenName+'</i><p>'+a.content+'</p></td><td width="200px"><span class="k_time">';
			
			var now = new Date();
			var old = new Date(a.createTimeStr);
			var m_date = parseInt((now.getTime() - old.getTime())/1000/60);
			if(m_date >= 100){
				m_date = a.createTimeStr;
			}else{
				m_date += "分钟前";
			}
			
			tr += m_date+'</span>'
				+'<shiro:hasPermission name="customer_clue_delete_button"><a href="javascript:;" onclick="delClueWeibo('+a.id+')" class="s_icon_delect"></a></shiro:hasPermission>'
				+'<shiro:hasPermission name="customer_clue_chat_button"><a href="javascript:;" customerId="'+a.customerId+'" actionId="0" clueWeiboId="'+a.id+'"  class="s_icon_dialogue"></a></shiro:hasPermission></td></tr>';
		}
	}
	
	if(tr != ""){
		$("table:eq(0) tbody").html(tr);
		for ( var i = 0; i < keyword_count.length; i++) {
			var a = keyword_count[i];
			$('.s_all>table').highlight(a.keyWord);
		}
	}else{
		$("table:eq(0) tbody").html('<div class="k_empty_content"><img src="<%=path%>/bc/images/k_search.png" /><p>暂无内容</p></div>');
	}
}

function activityFirst(key_word_list,keyword_count){
	var total = 0;
	
	var startStr = "";
	var endStr = "";
	
	$(".s_all:eq(1)>.s_all_title").html('<li class="s_all_on" keyWord=""><a href="javascript:;">全部</a></li>');
	
	//这个循环计算总数
	for ( var i = 0; i < keyword_count.length; i++) {
		if(i >= 5){
			break;
		}
		var a = keyword_count[i];
		total += a.count;
	}
	
	for ( var i = 0; i < keyword_count.length; i++) {
		if(i >= 5){
			break;
		}
		var a = keyword_count[i];
		
		var length_baifenbi = a.count/total*100;
        if(length_baifenbi == 0)
        	length_baifenbi = 2;
        if(total == 0)
        	length_baifenbi = 2;
		
        $(".s_all:eq(1)>.s_all_title").append('<li keyWord="'+a.activityName+'"><a href="javascript:;">'+a.activityName+'</a></li>');
		startStr += '<li keyWord="'+a.activityName+'"><i><a href="javascript:;">'+a.activityName+'</a></i><div class="progressbar_1"><div class="bar" style="width:'+length_baifenbi+'%;"></div></div><em style="padding-left:10px">'+a.count+'条</em></li>'
	}
	
	$(".s_all:eq(1)>.s_all_title").append('<b><a href="<%=path%>/api/clue_customer/clue_activityView">更多</a></b>');

	$(".s_clue:eq(1)>p>span").text(total);
	
	if(startStr+endStr != ""){
		$(".s_source:eq(1)").html(startStr+endStr);
	}else{
		$(".s_source:eq(1)").html('<div class="k_empty_content"><img src="<%=path%>/bc/images/icon_hd.png" /><p>您还没有活动 <a href="<%=path%>/api/bm/ui/createActivity1" target="_parent">去创建活动></a></p></div>');
		
		$(".s_all:eq(1)>.s_all_title").html('<span>暂无活动</span>');
		$(".s_all:eq(1)").addClass("k_empty");
	}
	
	$(".s_all:eq(1)>.s_all_title>li[keyWord='"+keyWord_activity+"']").addClass('s_all_on').siblings().removeClass();
}

function activitySecond(weibo_clue_list){
	var tr = "";
	for(var i = 0; i < weibo_clue_list.length; i++){
		var a = weibo_clue_list[i];
		if(a.content.length>=64){
			a.content = a.content.substr(0,60)+"...";
		}
		tr += '<tr><td><img style="height:50px;width:50px;" src="'+((a.avatar == null || a.avatar == undefined || a.avatar == "") ? "<%=path%>/images/000head_pic.png" : a.avatar)+'" /><a href="javascript:;">'+a.name+'</a></td><td class="s_red">'+a.content+'</td><td>'+getSourceTitle(a.source)+'</td><td width="200px"><span class="k_time">';
		
		var now = new Date();
		var old = new Date(a.createTimeStr);
		var m_date = parseInt((now.getTime() - old.getTime())/1000/60);
		if(m_date >= 100){
			m_date = a.createTimeStr;
		}else{
			m_date += "分钟前";
		}
		
		tr += m_date+'</span>'
			+'<shiro:hasPermission name="customer_clue_delete_button"><a href="javascript:;" onclick="delClueActivity('+a.id+')" class="s_icon_delect"></a></shiro:hasPermission>'
			+'<shiro:hasPermission name="customer_clue_chat_button"><a href="javascript:;" customerId="'+a.customerId+'" actionId="'+a.id+'" clueWeiboId="0" class="s_icon_dialogue"></a></shiro:hasPermission></td></tr>';
	}
	if(tr != ""){
		$("table:eq(1) tbody").html(tr);
	}else{
		$("table:eq(1) tbody").html('<div class="k_empty_content"><img src="<%=path%>/bc/images/k_search.png" /><p>暂无内容</p></div>');
	}
}


function getSourceTitle(source){
	console.log("-----来源--》"+source);
	var title;
	switch (source) {
	case "1":
		title="微博";
		break;
	case "2":
		title="微信";
		break;
	case "3":
		title="QQ";
		break;
	case "4":
		title="活动";
		break;
	case "5":
		title="pc网页";
		break;
	case "6":
		title="短信";
		break;
	default:
		title="未知";
		break;
	}
	return title;
	
}


function hideWeibo(){
	$.post("${pageContext.request.contextPath}/api/weibo/updatefirstpage",{back5:'0'},function(data){
		init();
	});
}

function delClueWeibo(id){
	$(".j_popup_box").show();
	$(".j_popup_box .j_popup_box_confirm").unbind("click");
	$(".j_popup_box .j_popup_box_confirm").one("click",function(){
		$.post("<%=path%>/api/clue_customer/delClueWeibo",{clueWeiboId:id},function(data){
			init();
			$(".j_popup_box").hide();
		});
	});
	
}

function delClueActivity(id){
	$(".j_popup_box").show();
	$(".j_popup_box .j_popup_box_confirm").unbind("click");
	$(".j_popup_box .j_popup_box_confirm").one("click",function(){
		$.post("<%=path%>/api/clue_customer/delClueActivity",{clueActivityId:id},function(data){
			init();
			$(".j_popup_box").hide();
		});
	});
}
var clueNum;
//获取智能营销
function getMarket(){
	html='';
	var url = "<%=path%>/api/smart_market/queryHomeMarket";
	$.post(url, {
		"access_token" : access_token,
		"cid" : cid,
		"uid" : uid,
	}, function(data) {
		var datas = JSON.parse(data);
		if(datas.error_code=="0"){
			clueNum=datas.clueNum;
			setMarketHtml(datas.data);
		}else{
			
		}
	},'text');
}

function setMarketHtml(data){
		/* var activityData=JSON.parse(data[i].activityData); */
		var activity1=data.activityData[0];
		var activity2=data.activityData[1];
		var activity3=data.activityData[2];
		//解析活动二
		var send_time1= JSON.parse(activity1.send_time);
		var send_time2= JSON.parse(activity2.send_time);
		var send_time3= JSON.parse(activity3.send_time);
		console.log(777777777777);
		var send_obj1= JSON.parse(activity1.send_object);
		var send_obj2= JSON.parse(activity2.send_object);
		var send_obj3= JSON.parse(activity3.send_object);
		console.log(222222222);
		var activity_send_time1=getSendTime(send_time1);
		var activity_send_time2=getSendTime(send_time2);
		var activity_send_time3=getSendTime(send_time3);
		
		var activity_send_obj1=getSendObj(send_obj1);
		var activity_send_obj2=getSendObj(send_obj2);
		var activity_send_obj3=getSendObj(send_obj3);
		
		var behavior_rule2=getBehaviorRule(activity2.behavior_rule);
		var behavior_rule3=getBehaviorRule(activity3.behavior_rule);
		
		var html='';
		
		html+='<div class="item-bottom top-title">';
		html+='<p><span>'+clueNum+'</span> 条线索源于智能营销-'+data.name+'</p>';
		html+='<div class="k_right"> ';
		/* html+='<input type="checkbox" name="firstpage" value="1" style="margin:0;">首页显示</label>'; */
		html+='<a target="_parent" href="javascript:;" market_id='+data.market_id+' processDefintionId='+data.definition_id+' class="edit_market">编辑</a>';
		html+='<a target="_parent" id="manageId'+data.market_id+'" href="javascript:;" market_id='+data.market_id+' activity_id='+activity1.id+' rule_id='+activity1.rule_id+' status='+data.status+' processDefintionId="'+data.definition_id+'" '+(data.status==1?"class='manage_market'>停用":"class='manage_market k_red'>启用")+'</a>';
		html+='<a target="_parent" href="javascript:;" market_id='+data.market_id+' processDefintionId='+data.definition_id+' class="copy_market">复制</a></div></div>';
		html+='<div class="k_box">';
		html+=' <div style="display:flex;">';
		html+=' <div class="top-line"></div></div>';
		html+='<div style="display:flex;">';
		html+=' <div class="item-block bg1 model-height">';
		html+='<a target="_parent" style="text-decoration:underline;" href="<%=path%>/view/ui/activityDetail?type=1&activity_id='+activity1.id+'"><font color=white>'+activity1.name+'</font></a>';
		html+='<div class="model-con">';
		html+='<p>打开次数：<span>'+activity1.browse_number+'</span></p>';
		html+='<p>转发次数：<span>'+activity1.browse_number+'</span></p>';
		html+='<p>提交表单数：<span>'+activity1.submit_numer+'</span></p>';
		html+='<p>核销人数：<span>'+activity1.write_off_num+'</span></p>';
		html+='<p>累计消费金额：<span>'+activity1.consumption_amount+'</span></p></div>';
		html+='<div class="info-hover"></div>';
		html+='<ul><li>发送方式 &nbsp; <span>'+getSendType(activity1.send_type)+'</span></li>';
		html+='<li>发送对象 &nbsp; <span>'+activity_send_obj1+'</span></li>';
		html+='<li>发送时间 &nbsp; <span>'+activity_send_time1+'</span></li></ul></div>';
		html+='<div class="item-block line-block1">';
		html+='<i class="into s_into"></i><div class="prism1">'+behavior_rule2+'</div><i class="into"></i></div>';
		html+='<div class="item-block bg2 model-height">';
		html+='<a target="_parent" style="text-decoration:underline;" href="<%=path%>/view/ui/activityDetail?type=1&activity_id='+activity2.id+'"><font color=white>'+activity2.name+'</font></a>';
		html+='<div class="date date-left1" title="'+activity_send_time2+'" style="white-space:nowrap;text-overflow:ellipsis;-o-text-overflow:ellipsis;overflow: hidden;">'+activity_send_time2+'</div>';
		html+='<div class="model-con">';
		html+='<p>打开次数：<span>'+activity2.browse_number+'</span></p>';
		html+='<p>转发次数：<span>'+activity2.browse_number+'</span></p>';
		html+='<p>提交表单数：<span>'+activity2.submit_numer+'</span></p>';
		html+='<p>核销人数：<span>'+activity2.write_off_num+'</span></p>';
		html+='<p>累计消费金额：<span>'+activity2.consumption_amount+'</span></p></div>';
		html+='<div class="info-hover"></div>';
		html+='<ul><li>发送方式 &nbsp; <span>'+getSendType(activity2.send_type)+'</span></li>';
		html+='<li>发送对象 &nbsp; <span>'+activity_send_obj2+'</span></li>';
		html+='<li>发送时间 &nbsp; <span>'+activity_send_time2+'</span></li></ul></div>';
		html+='<div class="item-block"></div>';
		html+='<div class="item-block bg3 model-height">';
		html+='<a target="_parent" style="text-decoration:underline;" href="<%=path%>/view/ui/activityDetail?type=1&activity_id='+activity3.id+'"><font color=white>'+activity3.name+'</font></a>';
		html+='<i class="into k_into"></i><div class="date" title="'+activity_send_time3+'" style="white-space:nowrap;text-overflow:ellipsis;-o-text-overflow:ellipsis;overflow: hidden;">'+activity_send_time3+'</div>';
		html+='<div class="model-con">';
		html+='<p>打开次数：<span>'+activity3.browse_number+'</span></p>';
		html+='<p>转发次数：<span>'+activity3.browse_number+'</span></p>';
		html+='<p>提交表单数：<span>'+activity3.submit_numer+'</span></p>';
		html+='<p>核销人数：<span>'+activity3.write_off_num+'</span></p>';
		html+='<p>累计消费金额：<span>'+activity3.consumption_amount+'</span></p></div>';
		html+='<div class="info-hover"></div>';
		html+='<ul><li>发送方式 &nbsp; <span>'+getSendType(activity3.send_type)+'</span></li>';
		html+='<li>发送对象 &nbsp; <span>'+activity_send_obj3+'</span></li>';
		html+='<li>发送时间 &nbsp; <span>'+activity_send_time3+'</span></li>';
		html+='</ul></div></div></div>';
		$('.pad2').html(html);
}
//获取发送时间

$(document).on('mouseover', '.info-hover', function() {
	$(this).next().show();
});
$(document).on('mouseleave', '.info-hover', function() {
	    $(this).next().hide();
});

//获取发送时间
function getSendTime(send_time){
	var activity_send_time;
	for (var key in send_time)
    {
        switch (key) {
		case "right_now":
			activity_send_time="立刻";
			break;
		case "distance_last_consume":
			activity_send_time="距离上一次消费"+send_time[key]+"天";
			break;
		case "distance_first_consume":
			activity_send_time="距离第一次消费"+send_time[key]+"天";
			break;
		case "distance_last_activity":
			activity_send_time="距离上一活动"+send_time[key]+"天";
			break;
		case "date":
			activity_send_time=send_time[key];
			break;
		case "birthday":
			activity_send_time="生日";
			break;
		default:
			activity_send_time="立刻";
			break;
		}
    }
	return activity_send_time;
}
//获取发送方式
function getSendType(sendType){
	var send_typeTemp=sendType.split(",");
	var send_type="";
	for(var i in send_typeTemp){
		switch (send_typeTemp[i]) {
		case "sms":
			send_type=send_type+","+"短信";
			break;
		case "email":
			send_type=send_type+","+"邮箱";
			break;
		case "weibo":
			send_type=send_type+","+"微博";
			break;

		default:
			break;
		}
		
	}
	send_type=send_type.replace(",","");
	return send_type;
	
}
//获取行为规则
function getBehaviorRule(behavior_rule){
	var rule;
	switch (behavior_rule) {
	case 0:
		rule="无";
		break;
	case 1:
		rule="参加上一活动";
		break;
	case 2:
		rule="未参加上一活动";
		break;
		rule="无";
	default:
		break;
	}
	return rule;
}
//获取发送对象
function getSendObj(send_obj){
	var obj="";
	for (var key in send_obj){
		console.log("--------------------->"+key);
		switch (key) {
		case "trading_hours":
			console.log(send_obj[key]);
			var temp1=send_obj[key].split(",");
			for(var i in temp1){
				if(temp1[i]=="old_customer"){
					obj=obj+","+"老客户";
				}else if(temp1[i]=="new_customer")
					obj=obj+","+"新客户";
			}
			obj=obj.replace(",","");
			break;
		case "trading_frequency":
			var temp2=send_obj[key].split(",");
			for(var i in temp2){
				if(temp2[i]=="visitor"){
					obj=obj+","+"过客";
				}else if(temp2[i]=="frquenter"){
					obj=obj+","+"常客";
				}else if(temp2[i]=="loyal"){
					obj=obj+","+"忠诚客户";
				}
			}
			obj=obj.replace(",","");
			break;
		case "trading_amount":
			var temp3=send_obj[key].split(",");
			for(var i in temp3){
				if(temp3[i]=="main"){
					obj=obj+","+"主力";
				}else if(temp3[i]=="general"){
					obj=obj+","+"一般";
				}else if(temp3[i]=="scattered"){
					obj=obj+","+"零散";
				}
					
			}
			obj=obj.replace(",","");
			break;
		case "loss_status":
			var temp4=send_obj[key].split(",");
			for(var i in temp4){
				if(temp4[i]=="loss"){
					obj=obj+","+"流失客户";
				}else if(temp4[i]=="no_loss"){
					obj=obj+","+"未流失客户";
				}
					
			}
			obj=obj.replace(",","");
			break;

		default:
			break;
		}
	return obj;
	}
}

//复制
$(document).on('click', '.copy_market', function() {
	var market_id=$(this).attr("market_id");
	window.parent.location.href = "<%=path%>/api/bm/ui/createMarket?type=copy&market_id="+market_id;
});

//编辑
$(document).on('click', '.edit_market', function() {
	var market_id=$(this).attr("market_id");
	window.parent.location.href = "<%=path%>/api/bm/ui/createMarket?type=edit&market_id="+market_id;
});
//启用停用
$(document).on('click', '.manage_market', function() {
	var market_id=$(this).attr("market_id");
	var status=$(this).attr("status");
	var processDefintionId=$(this).attr("processDefintionId");
	var rule_id=$(this).attr("rule_id");
	var activity_id=$(this).attr("activity_id");
	if(status==1){
		suspend(market_id, processDefintionId);
	}else{
		activte(market_id, processDefintionId,rule_id,activity_id);
	}
});

//启用活动
function activte(market_id,processDefintionId,rule_id,activity_id) {
	var url = "<%=path%>/api/smart_market/activate";
	var manageId="#manageId"+market_id;
	$.post(url, {
		"access_token" : access_token,
		"cid" : cid,
		"uid" : uid,
		"market_id" : market_id,
		"processDefintionId" : processDefintionId,
		"rule_id" : rule_id,
		"activity_id" : activity_id,
	}, function(data) {
		
		var datas = JSON.parse(data);
		if (datas.error_code == "0") {
			$(manageId).text("停用");
			$(manageId).attr("status","1");
			$(manageId).css("color","#03a9f4");
		} else {
		}
	});
}
//停止活动
function suspend(market_id, processDefintionId) {
	var url = "<%=path%>/api/smart_market/suspend";
	var manageId="#manageId"+market_id;
	$.post(url, {
		"access_token" : access_token,
		"cid" : cid,
		"uid" : uid,
		"market_id" : market_id,
		"processDefintionId" : processDefintionId,
	}, function(data) {
		var datas = JSON.parse(data);
		if (datas.error_code == "0") {
			$(manageId).text("启用");
			$(manageId).attr("status","2");
			$(manageId).css("color","#ff7469");
		} else {
		}
	});
}

</script>
</html>